<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
</head>
<body>
    <form autocomplete="off">
        姓名：<input type="text" id="username">
        <span id="uSpan"></span>
        <br>
        密码：<input type="password" id="password">
        <br>
        <input type="submit" value="注册">
    </form>
</body>
<script>
    document.getElementById("username").onblur=function () {
        let xmlHttp = new XMLHttpRequest();

        let username =document.getElementById("username").value;
        xmlHttp.open("GET","userServlet01?username="+username,true);

        xmlHttp.send();

        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4 && xmlHttp.status==200) {
                document.getElementById("uSpan").innerHTML=xmlHttp.responseText;
            }
        }
    }
</script>
</html>